define(function (require, exports, module) {

    var tpl = require('../../tpl/member/movieTicket.tpl');//载入tpl模板
    var curId = $("#myMovieTicketDiv");
    var pagerid = "kkpagerMovieTicket";
    //初始化显示表格、搜索
    require.async(['./showTable', './search'], function (showTable, search) {
        search.search('/movieTicket/myMovieTicketList.html?', tpl, curId, pagerid);
        $(".my_movie_ticket").click(function () {
            showTable.ajaxUrl('/movieTicket/myMovieTicketList.html?status=' + 99, tpl, curId, pagerid);
        });
        $('.movie-ticket-form').validate({
            rules: {
                'movie-ticket': {
                    required: true
                }
            },
            messages: {
                'movie-ticket': {
                    required: '*请输入兑换券号码'
                }
            },
            errorPlacement:function(error,element){
                $('.movie_error').text($(error).text());
                setTimeout(function(){$('.movie_error').text('')},3000);
            },
            submitHandler: function (form) {

                //layer.alert('敬请期待');
                //return false;
                $(form).ajaxSubmit({
                    type: "post",
                    dataType: "json",
                    success: function (data) {
                        var resultMsg = data.msg || "";
                        layer.alert(resultMsg,function(){
                        	if(data.result==true){
                        		window.location.href = "/member/redpacket/availableRedEnvelope.html?tab=4";
                        	}
                        	layer.closeAll();
                        });
                    }
                });
            }

        })
    });

    //兑换券兑换详情
    $(".movie_ticket_detail").live("click", function(){
        var req_data = {};
        req_data.exchangeCode = $(this).parent().parent().find(".exchangeCode").html();
        $.post("/movieTicket/movieTicketDetail.html", req_data, function(data, status){
            data = JSON.parse(data);
            window.layer.open({
                type: 1,
                closeBtn: 1,
                title: "电影票兑换详情",
                area: ['450px', '480px'],
                border: [1, 1, '#cecfd0'],
                content:'<div class="tipsWrap w450"><div class="tipsTxt"><ul>' +
                            '<li style="text-align: left; margin-left:50px; font-size:small"><b>兑换码：</b>' + data.exchangeCode + '</li>' +
                            '<li style="text-align: left; margin-left:50px; font-size:small"><b>取票码：</b>' + data.fetchCode + '</li>' +
                            '<li style="text-align: left; margin-left:50px; font-size:small"><b>取票手机号：</b>' + data.fetchPhone + '</li>' +
                            '<li style="text-align: left; margin-left:50px; font-size:small"><b>电影名称：</b>' + data.movieName + '</li>' +
                            '<li style="text-align: left; margin-left:50px; font-size:small"><b>影院：</b>' + data.cinema + '</li>' +
                            '<li style="text-align: left; margin-left:50px; font-size:small"><b>观看时间及厅号：</b>' + data.scene +'</li>' +
                            '<li style="text-align: left; margin-left:50px; font-size:small"><b>座位：</b>' + data.seat +'</li>' +
                            '</ul><div class="tipsBtnBar"><a href="javascript:;" class="cancleBtn">确定</a></div></div></div>'
            });
            //关闭窗口
            $(".cancleBtn").click(function(){
                layer.closeAll();
            });
        });
    });
});